

/*
 *check data when submit 
 *
 *
 */
jQuery("#tb-search-flights").click(function() {

    var dataTrue = 1;
    var typeFlights = 0;
    var siteUrl = jQuery('#site_url').val();    
    var dsstartLocation = new Array();
    var dsendLocation = new Array();
    var dsstartDate = new Array();
    var dsEndDate = new Array();
    var url_ajax = siteUrl + "/wp-content/themes/travel_donald/ajax/request_a_quote.php";

    //var typeFlights1 = jQuery('#typeFlights1').checked ; 
    /// alert(typeFlights1);

    var name = jQuery("#name").val();


    if (name == "") {
        jQuery("#error-name").html('Please you check Name');
        dataTrue = 0;
    }
    else
    {
        jQuery("#error-name").html('');
    }

    var email = jQuery("#txt-email").val();
    if (email == "")
    {
        jQuery("#error-email").html('Please you check Email');
        dataTrue = 0;

    }
    else
    {
        var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (!re.test(email)) {

            jQuery("#error-email").html('The email is not correct');
            dataTrue = 0;
        }
        else {

            jQuery("#error-email").html('');


        }

    }
    
    var phone = jQuery("#txt-phone").val();
    
    if(phone == ""){
           
         jQuery("#error-phone").html('Please you check Phone');
         dataTrue = 0;
    }
    else{
         jQuery("#error-phone").html('');
    }
    
    
      

    if (jQuery('#typeFlights1').is(":checked"))
    {
        typeFlights = 1;

    }
    if (jQuery('#typeFlights2').is(":checked"))
    {
        typeFlights = 2;

    }
    if (jQuery('#typeFlights3').is(":checked"))
    {
        typeFlights = 3;

    }
    if (typeFlights == '0') {

        jQuery("#error-type-flight").html('Please you check type flights');
        dataTrue = 0;
    }
    else {
        jQuery("#error-type-flight").html('');
    }



    if (typeFlights == 2)
    {
        var startLocation = jQuery('#leaving-from').val();
        if (startLocation == "") {
            jQuery("#error-leaving-form").html('Leaving from must not be  blank');
            dataTrue = 0;

        } else {
            jQuery("#error-leaving-form").html('');
        }

        var endLocation = jQuery('#going-to').val();

        if (endLocation == "")
        {
            jQuery('#error-going-to').html('Going to must not be blank');
            dataTrue = 0;
        }
        else
        {
            jQuery("#error-going-to").html('');

        }
        var startDate = jQuery('#departure-date').val();
        if (startDate == "") {
            jQuery("#error-start-time").html('Departure date must not be blank<br/>');
            dataTrue = 0;
        }
        else {
            jQuery("#error-start-time").html("");
        }

        var endDate = jQuery("#return-date").val();
        if (endDate == "") {

            jQuery("#error-end-time").html('Return date must not be blank');
            dataTrue = 0;
        }
        else {
            jQuery('#error-end-time').html("");

        }

        for (var i = 1; i <= 4; i++) {
            jQuery("#error-leaving-form" + i).html('');
            jQuery("#error-going-to" + i).html('');
            jQuery("#error-start-time" + i).html("");
            jQuery('#error-end-time' + i).html("");
        }
    }
    else if (typeFlights == 1) {
        var startLocation = jQuery('#leaving-from').val();
        if (startLocation == "") {
            jQuery("#error-leaving-form").html('Leaving from must not be  blank');
            dataTrue = 0;

        } else {
            jQuery("#error-leaving-form").html('');
        }

        var endLocation = jQuery('#going-to').val();
        if (endLocation == "")
        {
            jQuery('#error-going-to').html('Going to must not be blank');
            dataTrue = 0;
        }
        else
        {
            jQuery("#error-going-to").html('');

        }
        var startDate = jQuery('#departure-date').val();
        if (startDate == "") {
            jQuery("#error-start-time").html('Departure date must not be blank<br/>');
            dataTrue = 0;
        }
        else {
            jQuery("#error-start-time").html("");
        }


        for (var i = 1; i <= 4; i++) {
            jQuery("#error-leaving-form" + i).html('');
            jQuery("#error-going-to" + i).html('');
            jQuery("#error-start-time" + i).html("");
            jQuery('#error-end-time' + i).html("");
        }
    }
    else
    {

        var idStt = jQuery("#morest").val();
        for (var i = 1; i <= idStt; i++) {


            var startLocation = jQuery('#leaving-from' + i).val();

            dsstartLocation.push(startLocation);

            if (startLocation == "") {
                jQuery("#error-leaving-form" + i).html('Leaving from must not be  blank');
                dataTrue = 0;

            }
            else {
                jQuery("#error-leaving-form" + i).html('');
            }


            var endLocation = jQuery('#going-to' + i).val();
            dsendLocation.push(endLocation);

            if (endLocation == "")
            {
                jQuery('#error-going-to' + i).html('Going to must not be blank');
                dataTrue = 0;
            }
            else
            {
                jQuery("#error-going-to" + i).html('');

            }

            var startDate = jQuery('#departure-date' + i).val();

            dsstartDate.push(startDate);

            if (startDate == "") {
                jQuery("#error-start-time" + i).html('Departure date must not be blank<br/>');
                dataTrue = 0;
            }
            else {
                jQuery("#error-start-time" + i).html("");
            }

            var endDate = jQuery("#return-date" + i).val();

            dsEndDate.push(endDate);

            if (endDate == "") {

                jQuery("#error-end-time" + i).html('Return date must not be blank');
                dataTrue = 0;
            }
            else {
                jQuery('#error-end-time' + i).html("");

            }

            jQuery("#error-leaving-form").html('');
            jQuery("#error-going-to").html('');
            jQuery("#error-start-time").html("");
            jQuery('#error-end-time').html("");
        }
    }

    // alert(dsstartLocation);
    // return;

    var adult = jQuery("#Adult").val();
    var children = jQuery('#numCHD').val();
    var infant = jQuery("#infant").val();
    var classa = jQuery("#class").val();
    var city = jQuery("#city").val();
    //alert(startLocation);
    if (dataTrue == 1) {

        if (typeFlights == 1)
        {

            jQuery.post(url_ajax, {typeFlights: typeFlights,name:name,email:email,phone:phone,startLocation: startLocation, endLocation: endLocation, startDate: startDate, adult: adult, children: children, infant: infant, class: classa, city: city}, function(data) {

                // alert(data);
                jQuery("#name").val("");
                jQuery("#txt-email").val("");
                jQuery("#txt-phone").val("");
                jQuery("#leaving-from").val("");
                jQuery("#going-to").val("");
                jQuery("#departure-date").val("");
                jQuery("#return-date").val("");
                
                jQuery("#leaving-from1").val("");
                jQuery("#going-to1").val("");
                jQuery("#departure-date1").val("");
                jQuery("#return-date1").val("");
                
                 jQuery("#leaving-from2").val("");
                jQuery("#going-to2").val("");
                jQuery("#departure-date2").val("");
                jQuery("#return-date2").val("");
                
                 jQuery("#leaving-from3").val("");
                jQuery("#going-to3").val("");
                jQuery("#departure-date3").val("");
                jQuery("#return-date3").val("");
                
                
                 jQuery("#leaving-from4").val("");
                jQuery("#going-to4").val("");
                jQuery("#departure-date4").val("");
                jQuery("#return-date4").val("");
                
                
                jQuery("#success-request_quote").modal();
               

            });
        }
        else if (typeFlights == 2)
        {
            //alert(2);
            jQuery.post(url_ajax, {typeFlights: typeFlights,name:name,email:email,phone:phone, startLocation: startLocation, endLocation: endLocation, startDate: startDate, endDate: endDate, adult: adult, children: children, infant: infant, class: classa, city: city}, function(data) {

                // alert(data);
                    jQuery("#name").val("");
                jQuery("#txt-email").val("");
                jQuery("#txt-phone").val("");
                jQuery("#leaving-from").val("");
                jQuery("#going-to").val("");
                jQuery("#departure-date").val("");
                jQuery("#return-date").val("");
                
                jQuery("#leaving-from1").val("");
                jQuery("#going-to1").val("");
                jQuery("#departure-date1").val("");
                jQuery("#return-date1").val("");
                
                 jQuery("#leaving-from2").val("");
                jQuery("#going-to2").val("");
                jQuery("#departure-date2").val("");
                jQuery("#return-date2").val("");
                
                 jQuery("#leaving-from3").val("");
                jQuery("#going-to3").val("");
                jQuery("#departure-date3").val("");
                jQuery("#return-date3").val("");
                
                
                 jQuery("#leaving-from4").val("");
                jQuery("#going-to4").val("");
                jQuery("#departure-date4").val("");
                jQuery("#return-date4").val("");
                
                jQuery("#success-request_quote").modal();

            });
        }
        else
        {
	    
            jQuery.post(url_ajax, {typeFlights: typeFlights,name:name,email:email,phone:phone,startLocation: dsstartLocation, endLocation: dsendLocation, startDate: dsstartDate, endDate: dsEndDate, adult: adult, children: children, infant: infant, class: classa, city: city}, function(data) {
                jQuery("#name").val("");
                jQuery("#txt-email").val("");
                jQuery("#txt-phone").val("");
                jQuery("#leaving-from").val("");
                jQuery("#going-to").val("");
                jQuery("#departure-date").val("");
                jQuery("#return-date").val("");
                
                jQuery("#leaving-from1").val("");
                jQuery("#going-to1").val("");
                jQuery("#departure-date1").val("");
                jQuery("#return-date1").val("");
                
                 jQuery("#leaving-from2").val("");
                jQuery("#going-to2").val("");
                jQuery("#departure-date2").val("");
                jQuery("#return-date2").val("");
                
                 jQuery("#leaving-from3").val("");
                jQuery("#going-to3").val("");
                jQuery("#departure-date3").val("");
                jQuery("#return-date3").val("");
                
                
                 jQuery("#leaving-from4").val("");
                jQuery("#going-to4").val("");
                jQuery("#departure-date4").val("");
                jQuery("#return-date4").val("");
                
                jQuery("#success-request_quote").modal();
                //  alert(data);

            });
        }


    }



});